package com.cslg.ac.demo.dao.user.team;

import com.cslg.ac.demo.dao.user.po.team.TeamInfoPO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TeamInfoDAO {
     String TEAMINFO_TABLE = "e_t_account_info";
     String SELECT_FIELD = "id,name,nature,address,code_number codeNumber,email,grade,etime,introduction,o_phone oPhone," +
             "image, proof";
     String SET_FIELD = "set name = #{name},nature = #{nature},address = #{address},code_number = #{codeNumber}," +
             "email = #{email},etime = #{etime},o_phone = #{oPhone}";
//     String SET_LONGANDLAT_FILEDS = "set longitude = #{longitude}, latitude = #{latitude}";

    @Insert({"insert into",TEAMINFO_TABLE,"(id) values(#{id})"})
    void insert(int id);

    @Select({"select ",SELECT_FIELD," from ",TEAMINFO_TABLE," where id = #{id}"})
    TeamInfoPO selectById(@Param("id") int id);

    @Select({"select ",SELECT_FIELD," from ",TEAMINFO_TABLE," where head_phone = #{phone}"})
    TeamInfoPO selectByPhone(@Param("phone") String phone);

    @Update({"update ",TEAMINFO_TABLE,SET_FIELD," where id = #{id}"})
    void updateBasicById(TeamInfoPO teamInfoPO);

    @Update({"update ",TEAMINFO_TABLE,"set name = #{name},address = #{address},etime = #{etime}," +
            "nature = #{nature},introduction = #{introduction} where id = #{id}"})
    void updateChange(TeamInfoPO teamInfoPO);

    @Update({"update ",TEAMINFO_TABLE,"set grade = #{grade} where id = #{id}"})
    void updateGrade(@Param("id")int id,@Param("grade") int grade);

    @Update({"update ",TEAMINFO_TABLE,"set introduction = #{introduction} where id = #{id}"})
    void updateIntroduction(@Param("id")int id,@Param("introduction") String introduction);

    @Update({"update ",TEAMINFO_TABLE,"set image = #{image} where id = #{id}"})
    void updateImage(@Param("id")int id,@Param("image") String image);

    @Update({"update ",TEAMINFO_TABLE,"set proof = #{proof} where id = #{id}"})
    void updateProof(@Param("id")int id,@Param("proof") String proof);

    @Select({"select id from ",TEAMINFO_TABLE," where email = #{email}"})
    TeamInfoPO selectByMail(String email);

    @Select({"select id from ",TEAMINFO_TABLE," where name like concat(concat('%',#{name}),'%') limit #{offset}, #{num}"})
    Integer[] selectIdByName(@Param("name")String name,@Param("offset") int offset, @Param("num") int num );

    @Select({"select id from ",TEAMINFO_TABLE,"where email = #{email}"})
    Integer selectIdByEmail(@Param("email")String email);

    @Select({"select id from ",TEAMINFO_TABLE," where address like concat(concat('%',#{address}),'%') limit #{offset}, #{num} "})
    Integer[] selectIdByAddress(@Param("address")String adress, @Param("offset") int offset, @Param("num") int num);

    @Select({"select id from ", TEAMINFO_TABLE, "limit #{offset}, #{num}"})
    List<Integer> selectTeam(@Param("offset")int offset, @Param("num")int num);


}
